home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11885 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: tank.news.pipex.net!pipex!iol!usenet
  2. From: David Byrden <goyra@iol.ie>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Implicit Typecasting
  5. Date: 16 Mar 1996 21:44:51 GMT
  6. Organization: Ireland On-Line
  7. Message-ID: <4ifcoj$m8o@nuacht.iol.ie>
  8. References: <1996Mar16.203628.15187@mcs.drexel.edu>
  9. NNTP-Posting-Host: dialup-184.dublin.iol.ie
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22KIT (Windows; I; 16bit)
  14.  
  15.  
  16. ucphinni@mcs.drexel.edu (C. K. Phinnizee) wrote:
  17.  
  18. >class llNode {
  19. >    typedef llNode ll;
  20. >    public:
  21. >        llNode(ll * anext = NULL) { nextptr = anext;}
  22. >        ll * next(void) { return nextptr;}
  23. >        ll * next(ll * anext) { return nextptr = anext;}
  24. >        ... cut code ...
  25. >    private:
  26. >        ll * nextptr;
  27. >};
  28.  
  29.  
  30. >class dlNode : public llNode {
  31. >    typedef dlNode dl;
  32. >    public:
  33. >        dlNode(dl * aprev = NULL,dl * anext = NULL) 
  34. >                 : ll((ll *) anext)
  35.  
  36.  
  37.    The cast from dl to ll is not necessary! C++ will cast it implicitly 
  38. because ll is a base of dl.
  39.  
  40.  
  41.  
  42.  
  43. >        dl * prev(void) { return (dl *) prevptr.next();}
  44.  
  45.    Can't avoid this cast.
  46.  
  47.  
  48. >        dl * prev(dl * aprev) 
  49. >                { 
  50. >                     return (dl *) prevptr.next((dl *) aprev);
  51. >                }
  52.  
  53.  
  54.      Why cast aprev? It is already a  dl*
  55.  
  56.  
  57.      To sum up; you need only perform the casts from ll to dl. They are 
  58. necessary because only YOU know that a particular ll is really a dl. These 
  59. casts will have no runtime cost, so things are not too bad.
  60.  
  61.  
  62.                                             David
  63.  
  64.  
  65.